var t = n(require("../../../../@babel/runtime/regenerator")),
  e = require("../../../../@babel/runtime/helpers/asyncToGenerator"),
  r = n(require("../../../../config/index")),
  a = require("../../../../services/user-service");
function n(t) {
  return t && t.__esModule ? t : { default: t };
}
Component({
  properties: {
    activeUrl: {
      type: String,
      value: "",
      observer: function (t) {
        this.addImg(t);
      },
    },
  },
  data: {
    CDN: r.default.CDN,
    swiperCurrent: 3,
    circleCurrent: 3,
    imgSrc: "".concat(r.default.CDN, "/account/add_avatar.png"),
    imgList: [
      "".concat(r.default.CDN, "/account/avatar0.png"),
      "".concat(r.default.CDN, "/account/avatar1.png"),
      "".concat(r.default.CDN, "/account/avatar2.png"),
      "".concat(r.default.CDN, "/account/avatar3.png"),
      "".concat(r.default.CDN, "/account/avatar4.png"),
      "".concat(r.default.CDN, "/account/avatar5.png"),
    ],
  },
  methods: {
    changeCurrent: function (t) {
      console.log(t, "e");
      var e,
        r = this.data.imgList;
      (e = t.detail.current),
        this.setData({ circleCurrent: e, swiperCurrent: e }),
        this.triggerEvent("changeAvatar", { avatarUrl: r[e] });
    },
    goBefore: function () {
      var t = this.data.imgList,
        e = this.data.swiperCurrent;
      e > 0 &&
        (console.log(e, "current"),
        this.setData({ circleCurrent: e - 1, swiperCurrent: e - 1 }),
        this.triggerEvent("changeAvatar", { avatarUrl: t[e - 1] }));
    },
    goNext: function () {
      var t = this.data.imgList,
        e = this.data.swiperCurrent;
      e < t.length - 1 &&
        (this.setData({ circleCurrent: e + 1, swiperCurrent: e + 1 }),
        console.log(t),
        console.log(t[e + 1]),
        this.triggerEvent("changeAvatar", { avatarUrl: t[e + 1] }));
    },
    onChooseAvatar: function (r) {
      var n = this;
      return e(
        t.default.mark(function e() {
          var i, c, s;
          return t.default.wrap(function (t) {
            for (;;)
              switch ((t.prev = t.next)) {
                case 0:
                  if ((console.log(r), (i = r.detail.avatarUrl))) {
                    t.next = 5;
                    break;
                  }
                  return (
                    wx.showToast({
                      title: "获取图片失败",
                      icon: "none",
                      duration: 2500,
                    }),
                    t.abrupt("return")
                  );
                case 5:
                  return (t.next = 7), (0, a.upload)(i);
                case 7:
                  (c = t.sent),
                    (s = n.data.imgList).push(c),
                    n.setData({
                      imgList: s,
                      swiperCurrent: s.length - 1,
                      circleCurrent: s.length - 1,
                    }),
                    n.triggerEvent("changeAvatar", {
                      avatarUrl: s[s.length - 1],
                    });
                case 12:
                case "end":
                  return t.stop();
              }
          }, e);
        }),
      )();
    },
    addImg: function (t) {
      var e = this,
        r = this.data.imgList,
        a = !0;
      r.forEach(function (r, n) {
        r === t &&
          ((a = !1), e.setData({ swiperCurrent: n, circleCurrent: n }));
      }),
        a &&
          (r.push(t),
          this.setData({
            imgList: r,
            swiperCurrent: r.length - 1,
            circleCurrent: r.length - 1,
          }));
    },
  },
});
